# ==== main.py ====
from pipeline import Pipeline


def test_no_hazards():
    print("\n==== 测试1: 无数据冲突 ====")
    program = [
        # 初始化寄存器
        0x20010001,  # addi $1, $0, 1     # $1 = 1
        0x20020002,  # addi $2, $0, 2     # $2 = 2
        0x20030003,  # addi $3, $0, 3     # $3 = 3
        0x20040004,  # addi $4, $0, 4     # $4 = 4

        # 独立操作（无寄存器依赖）
        0x20250005,  # addi $5, $1, 5     # $5 = 1 + 5 = 6 (只依赖$1)
        0x20460006,  # addi $6, $2, 6     # $6 = 2 + 6 = 8 (只依赖$2)
        0x20670007,  # addi $7, $3, 7     # $7 = 3 + 7 = 10 (只依赖$3)
        0x20880008,  # addi $8, $4, 8     # $8 = 4 + 8 = 12 (只依赖$4)
        # 结束
        0x00000000,  # nop
    ]

    pipeline = Pipeline()
    pipeline.load_program(program)
    pipeline.run(max_cycles=15)


# def test_with_hazards():
#     print("\n==== 测试2: 有数据冲突 ====")
#     program = [
#         0x20010002,  # addi $1, $0, 2     # $1 = 2
#         0x20020003,  # addi $2, $0, 3     # $2 = 3
#         0x00221820,  # add  $3, $1, $2    # $3 = 5
#         0x00612020,  # add  $4, $3, $1    # $4 = 7 (依赖$3)
#         0x00822820,  # add  $5, $4, $2    # $5 = 10 (依赖$4)
#         0x00A33022,  # sub  $6, $5, $3    # $6 = 5 (依赖$5和$3)
#         0xAC060020,  # sw   $6, 32($0)    # 存储到地址32 (依赖$6)
#         0x8C070020,  # lw   $7, 32($0)    # 从地址32加载
#         0x00E34020,  # add  $8, $7, $3    # $8 = 10 (依赖$7)
#     ]

    # pipeline = Pipeline()
    # pipeline.load_program(program)
    # pipeline.run(max_cycles=20)


if __name__ == "__main__":
    test_no_hazards()
    # test_with_hazards()